﻿<UserControl x:Class="SilentWebsite.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    xmlns:viewModel="clr-namespace:SilentWebsite.ViewModels.Helpers"
             xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
             mc:Ignorable="d" d:DesignHeight="434" d:DesignWidth="767" Loaded="UserControlLoaded">

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="100"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.Resources>
            <viewModel:VisibilityConverter x:Key="VisibilityConverter" />
            <Style x:Key="TextBlockFontStyle" TargetType="TextBlock">
                <Setter Property="FontFamily" Value="Segoe UI"/>
                <Setter Property="Foreground" Value="Gray"/>
            </Style>
            <Style x:Key="NoFrameHyperlinkStyle" TargetType="HyperlinkButton">
                <Setter Property="Cursor" Value="Hand"/>
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="BorderBrush" Value="Transparent"/>
                <Setter Property="BorderThickness" Value="0"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="HyperlinkButton">
                            <Grid Background="{TemplateBinding Background}" Cursor="{TemplateBinding Cursor}">
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal" />
                                        <VisualState x:Name="MouseOver" />
                                        <VisualState x:Name="Pressed" />
                                        <VisualState x:Name="Disabled" />
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="FocusStates">
                                        <VisualState x:Name="Focused" />
                                        <VisualState x:Name="Unfocused" />
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <ContentPresenter x:Name="contentPresenter"
                                                  ContentTemplate="{TemplateBinding ContentTemplate}"
                                                  Content="{TemplateBinding Content}"
                                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                  Margin="{TemplateBinding Padding}" />
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>

        <HyperlinkButton Command="{Binding Back}" Width="36" Height="36"
                         Style="{StaticResource NoFrameHyperlinkStyle}"
                         Margin="15,25,15,15" Grid.Row="0" 
                         VerticalAlignment="Top"
                         HorizontalAlignment="Left">
            <Image Source="Resources/left_round.png" />
        </HyperlinkButton>

        <telerik:RadBusyIndicator BusyContent="{Binding BusyContent}" IsBusy="{Binding IsBusy}" IsIndeterminate="True" />

            <!-- Website Name -->
        <TextBlock Style="{StaticResource TextBlockFontStyle}"
                   Grid.Row="0" FontSize="36"
                   Text="Silent Website" Margin="70,15,5,5"
                   Width="Auto" Height="Auto"
                   HorizontalAlignment="Left"
                   VerticalAlignment="Top" />
        <!-- Menu -->
        <ItemsControl ItemsSource="{Binding MenuItems}"
                      Visibility="{Binding MenuVisibility, Converter={StaticResource VisibilityConverter}}"
                      HorizontalAlignment="Left"
                      VerticalAlignment="Top"
                      Margin="60,60,10,5">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"></StackPanel>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <HyperlinkButton Command="{Binding ElementName=LayoutRoot, Path=DataContext.Navigate}" CommandParameter="{Binding ElementName=MenuItem, Path=Text}" Style="{StaticResource NoFrameHyperlinkStyle}">
                        <TextBlock Name="MenuItem" Text="{Binding}" Style="{StaticResource TextBlockFontStyle}" FontSize="16" Margin="5"></TextBlock>
                    </HyperlinkButton>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>

        <!-- Authentication Block -->
        <Border Height="48" Width="48" BorderThickness="1" BorderBrush="Gray" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="20,-1,50,20">
            <Border.Background>
                <ImageBrush ImageSource="{Binding Avatart}" Stretch="None"></ImageBrush>
            </Border.Background>
        </Border>
        <HyperlinkButton Command="{Binding SignIn}"
                         Visibility="{Binding SignedInVisibility, Converter={StaticResource VisibilityConverter}}"
                         Style="{StaticResource NoFrameHyperlinkStyle}"
                         HorizontalAlignment="Right"
                         VerticalAlignment="Top"
                         Margin="20,0,110,20">
            <TextBlock Style="{StaticResource TextBlockFontStyle}" FontSize="22" Text="Sign In" />
        </HyperlinkButton >
        <HyperlinkButton Command="{Binding Register}"
                         Visibility="{Binding SignedInVisibility, Converter={StaticResource VisibilityConverter}}"
                         Style="{StaticResource NoFrameHyperlinkStyle}"
                         HorizontalAlignment="Right"
                         VerticalAlignment="Top"
                         Margin="20,28,110,20">
            <TextBlock Style="{StaticResource TextBlockFontStyle}" FontSize="14" Text="Register" />
        </HyperlinkButton>
        <HyperlinkButton Command="{Binding NavigateToProfile}"
                         Visibility="{Binding SignedOutVisibility, Converter={StaticResource VisibilityConverter}}"
                         Style="{StaticResource NoFrameHyperlinkStyle}"
                         HorizontalAlignment="Right"
                         VerticalAlignment="Top"
                         Margin="20,0,110,20">
            <TextBlock Style="{StaticResource TextBlockFontStyle}" FontSize="22" Text="{Binding Username}" />
        </HyperlinkButton >
        <HyperlinkButton Command="{Binding SignOut}"
                         Visibility="{Binding SignedOutVisibility, Converter={StaticResource VisibilityConverter}}"
                         Style="{StaticResource NoFrameHyperlinkStyle}"
                         HorizontalAlignment="Right"
                         VerticalAlignment="Top"
                         Margin="20,28,110,20">
            <TextBlock Style="{StaticResource TextBlockFontStyle}" FontSize="14" Text="Sign Out" />
        </HyperlinkButton>

        <!-- Navigation -->
        <navigation:Frame Name="NavigationFrame" Grid.Row="1" Margin="10"></navigation:Frame>
    </Grid>
</UserControl>